﻿@model Player

@{
    ViewBag.Title = "Player";
}

<div class="page-header">
    <h1>
        <span class="glyphicon glyphicon-user"></span> @Model.DisplayName <small>hcp: @Model.Hcp</small>
    </h1>
</div>
<div class="row">

    <div class="col-md-6">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4>Whats in the bag</h4>
            </div>
            <div class="panel-body">
                <b>@Html.DisplayNameFor(x => x.Driver)</b>
                @Html.DisplayFor(x => x.Driver)<br>
                <b>@Html.DisplayNameFor(x => x.Irons)</b>
                @Html.DisplayFor(x => x.Irons)<br>
                <b>@Html.DisplayNameFor(x => x.Putter)</b>
                @Html.DisplayFor(x => x.Putter)<br>
                <b>@Html.DisplayNameFor(x => x.Balls)</b>
                @Html.DisplayFor(x => x.Balls)<br>
            </div>
        </div>
    </div>

    <div class="col-md-6">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4>Ambitioner</h4>
            </div>
            <div class="panel-body">
                <b>@Html.DisplayNameFor(a => a.RoleModel)</b>
                @Html.DisplayFor(a => a.RoleModel)
                <br>
                <b>@Html.DisplayNameFor(a => a.StrongFeatures)</b>
                @Html.DisplayFor(a => a.StrongFeatures)
                <br>
                <b>@Html.DisplayNameFor(a => a.WeakFeatures)</b>
                @Html.DisplayFor(a => a.WeakFeatures)
                <br>
                <b>@Html.DisplayNameFor(a => a.SeasonObjective)</b>
                @Html.DisplayFor(a => a.SeasonObjective)
            </div>
        </div>
    </div>

    <div class="col-md-6">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4>Bedste runder</h4>
            </div>
            <div class="panel-body">
                @Model.BestRound
            </div>
        </div>
    </div>

    <div class="col-md-6">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4>kontaktinfo</h4>
            </div>
            <div class="panel-body">
                @Model.DisplayName<br>
                @Model.Address<br>
                @Model.ZipCode&nbsp;@Model.City<br>
                @if (User.Identity.IsAuthenticated)
                {
                    <br />
                    <i class="glyphicon glyphicon-phone"></i> <a href="tel:@Model.MobilePhone">@Model.MobilePhone</a><br>
                    <i class="glyphicon glyphicon-envelope"></i> <a href="mailto:@Model.Email">@Model.Email</a><br>
                }
                else
                {
                    <span>(log på for yderligere information)</span>
                }
            </div>
        </div>
    </div>
</div>

<a name="runder"></a>

<div class="panel panel-default">
    <div class="panel-heading">
        <h4>spillede runder</h4>
        <ul class="pagination">
            @for (int n = DateTime.UtcNow.Year; n > 2004; n--)
            {
                <li>@Html.ActionLink(n.ToString(), "Details", "Player", null, null, "runder", new { year = n }, null)</li>
            }
        </ul>
    </div>
    <div class="panel-body">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>dato</th>
                    <th>bane</th>
                    <th>event</th>
                    <th>brutto</th>
                    <th>netto</th>
                    <th>putts</th>
                    <th>stbl</th>
                    <th>privat?</th>
                </tr>
            </thead>
            <tbody>
                @foreach (Scorecard score in ViewBag.scores)
                {
                    <tr>
                        <td>
                            @Html.ActionLink(score.Round.DateEntry.ToShortDateString(), "Details", "Round", new { id = score.RoundId }, null)
                        </td>
                        <td>@score.Round.Course.Name</td>
                        <td>
                            @if (score.Round.Event != null)
                            {
                                @score.Round.Event.Name
                            }
                        </td>
                        <td>@score.Score</td>
                        <td>@score.NettoScore</td>
                        <td>@score.Putts</td>
                        <td>@score.StablefordPoints</td>
                        <td>
                            @if (score.Round.IsPrivate)
                            {
                                <i class="glyphicon glyphicon-check"></i>
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>

    </div>
    <div class="panel-footer">
        <div class="row">
            <div class="col-sm-8 col-md-5">
                <h3>Antal Putts, gennemsnit over år</h3>
                <canvas id="putts" class="stats" width="450" height="200"></canvas>

            </div>
            <div class="col-sm-8 col-md-5">
                <h3>Antal Slag, gennemsnit over år</h3>
                <canvas id="strokes" class="stats" width="450" height="200"></canvas>

            </div>
            <div class="col-sm-8 col-md-2">
                <h4>Legend</h4>
                <div id="legend">

                </div>
            </div>
        </div>
        
    </div>
</div>

@section Scripts {
    @Scripts.Render("~/bundles/chart")
    <script>
        $(document).ready(function () {
            var putts = document.getElementById("putts").getContext("2d");
            var strokes = document.getElementById("strokes").getContext("2d");
            var playerid = parseInt("@Model.Id");

            var legend;

            $.getJSON("/api/Stat/GetByPlayer", { playerid: playerid }, function (data) {
                var transformedData = transform(data);
                var puttChart = new Chart(putts).Line(transformedData[0]);
                var strokeChart = new Chart(strokes).Line(transformedData[1]);
                legend = strokeChart.generateLegend();
                $("#legend").append(legend);
            });

            function transform(data) {
                var out = [{
                    labels: [],
                    datasets: [{
                        label: "spiller",
                        fillColor: "rgba(151,187,205,0.2)",
                        strokeColor: "rgba(151,187,205,1)",
                        pointColor: "rgba(151,187,205,1)",
                        pointStrokeColor: "#fff",
                        pointHighlightFill: "#fff",
                        pointHighlightStroke: "rgba(151,187,205,1)",
                        data: []
                    },
                    {
                        label: "gns. thecup",
                        fillColor: "rgba(220,220,220,0.2)",
                        strokeColor: "rgba(220,220,220,1)",
                        pointColor: "rgba(220,220,220,1)",
                        pointStrokeColor: "#fff",
                        pointHighlightFill: "#fff",
                        pointHighlightStroke: "rgba(220,220,220,1)",
                        data: []
                    }]
                }, {
                    labels: [],
                    datasets: [{
                        label: "spiller",
                        fillColor: "rgba(151,187,205,0.2)",
                        strokeColor: "rgba(151,187,205,1)",
                        pointColor: "rgba(151,187,205,1)",
                        pointStrokeColor: "#fff",
                        pointHighlightFill: "#fff",
                        pointHighlightStroke: "rgba(151,187,205,1)",
                        data: []
                    },
                    {
                        label: "thecup gennemsnit",
                        fillColor: "rgba(220,220,220,0.2)",
                        strokeColor: "rgba(220,220,220,1)",
                        pointColor: "rgba(220,220,220,1)",
                        pointStrokeColor: "#fff",
                        pointHighlightFill: "#fff",
                        pointHighlightStroke: "rgba(220,220,220,1)",
                        data: []
                    }]
                }]

                for (var i = 0; i < data.length; i++) {
                    var entry = data[i];
                    out[0].labels.push(entry.year);
                    out[1].labels.push(entry.year);
                    // out 0 data 0 - user putts
                    out[0].datasets[0].data.push(Number(entry.putts).toFixed(2));
                    out[0].datasets[1].data.push(Number(entry.avgputts).toFixed(2));
                    // out 1 data 0 - user strokes
                    out[1].datasets[0].data.push(Number(entry.strokes).toFixed(2));
                    out[1].datasets[1].data.push(Number(entry.avgstrokes).toFixed(2));
                }

                return out;
            }

        });


    </script>
}